Release 10.1A: OpenEdge Development:
Programming Interfaces


Creating an XML document from database data

The first example outputs part of the Customer table of the Sports database.

sw-example.p 
/* Write out the Customer table of the Sports sample database  
   using the methods of the SAX-WRITER Object */ 
DEFINE VARIABLE hSAXWriter AS HANDLE. 
DEFINE VARIABLE lok AS LOGICAL. 
CREATE SAX-WRITER hSAXWriter. 
hSAXWriter:FORMATTED = TRUE. 
lok = hSAXWriter:SET-OUTPUT-DESTINATION("file", "sw-example.xml"). 
lok = hSAXWriter:START-DOCUMENT(). 
lok = hSAXWriter:START-ELEMENT("customers"). 
FOR EACH customer WHERE cust-num < 5: 
    lok = hSAXWriter:START-ELEMENT("customer"). 
    lok = hSAXWriter:INSERT-ATTRIBUTE("Cust-Num", STRING(Cust-Num)). 
    lok = hSAXWriter:INSERT-ATTRIBUTE("Name" , NAME). 
lok = hSAXWriter:WRITE-DATA-ELEMENT("Address", Address). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Address2", Address2).  
    lok = hSAXWriter:WRITE-DATA-ELEMENT("City", City). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("State", State). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Postal-Code", Postal-Code). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Country", Country). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Phone", Phone). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Contact", Contact). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Sales-Rep", Sales-Rep).   
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Credit-Limit", 
STRING(Credit-Limit)).  
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Balance", STRING(Balance)).   
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Terms", Terms). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Discount", STRING(Discount)). 
    lok = hSAXWriter:WRITE-DATA-ELEMENT("Comments", Comments).   
    lok = hSAXWriter:END-ELEMENT("customer"). 
END. 
lok = hSAXWriter:END-ELEMENT(“customers”). 
lok = hSAXWriter:END-DOCUMENT(). 
DELETE hSAXWriter. 

Here is a partial output from the sw-example.p program.

sw-example.xml (partial output) 
<?xml version="1.0"?> 
<customers> 
  <customer Cust-Num="1" Name="Lift Line Skiing"> 
    <Address>276 North Street</Address> 
    <Address2></Address2> 
    <City>Boston</City> 
    <State>MA</State> 
    <Postal-Code>02114</Postal-Code> 
    <Country>USA</Country> 
    <Phone>(617) 450-0087</Phone> 
    <Contact>Gloria Shepley</Contact> 
    <Sales-Rep>HXM</Sales-Rep> 
    <Credit-Limit>66700</Credit-Limit> 
    <Balance>42568</Balance> 
    <Terms>Net30</Terms> 
    <Discount>35</Discount> 
    <Comments>This customer is on credit hold.</Comments> 
  </customer> 
  <customer Cust-Num="2" Name="Urpon Frisbee"> 
    <Address>Rattipolku 3</Address> 
    <Address2></Address2> 
    <City>Valkeala</City> 
    <State>Uusimaa</State> 
    <Postal-Code>45360</Postal-Code> 
    <Country>Finland</Country> 
    <Phone>(60) 532 5471</Phone> 
    <Contact>Urpo Leppakoski</Contact> 
    <Sales-Rep>DKP</Sales-Rep> 
    <Credit-Limit>27600</Credit-Limit> 
    <Balance>17166</Balance> 
    <Terms>Net30</Terms> 
    <Discount>35</Discount> 
    <Comments>Ship all products 2nd Day Air.</Comments> 
  </customer> 
. 
. 
. 
</customers> 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095